package com.jixiantubu.adapter;

import image.SmartImageView;
import java.util.ArrayList;
import java.util.List;
import com.example.jixiantubu.R;
import com.jixiantubu.bean.Travelsbean;
import com.jixiantubu.util.MyApplication;
import com.lidroid.xutils.BitmapUtils;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Wo_YoujiAdapter extends BaseAdapter {
	Context context;// 上下文
	List<Travelsbean> list = new ArrayList<Travelsbean>();// 定义集合Travelsbean
	LayoutInflater mInflater;// 用来绑定布局
	ViewHolder viewHolder;// 初始化控件
	BitmapUtils bitmapUtils;
	ViewHolder mhHolder;
	
	
	
	
	public Wo_YoujiAdapter(Context context, List<Travelsbean> list) {
		super();
		this.context = context;
		this.list = list;
		// 绑定上下文
		mInflater = LayoutInflater.from(context);
		bitmapUtils = new BitmapUtils(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	class ViewHolder {
		SmartImageView imageView;
		TextView textView1, textView2, textView3;
	}
	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		if (arg1 == null) {
			arg1 = mInflater.inflate(R.layout.wo_youji_item, null);
			mhHolder = new ViewHolder();
			mhHolder.imageView = (SmartImageView) arg1
					.findViewById(R.id.wo_shoucang_tupian);
			mhHolder.textView1 = (TextView) arg1
					.findViewById(R.id.wo_youji_biaoti);
			mhHolder.textView2 = (TextView) arg1
					.findViewById(R.id.wo_youji_shijian);
			
			arg1.setTag(mhHolder);

		} else {

			mhHolder = (ViewHolder) arg1.getTag();
		}
		mhHolder.textView1.setText(list.get(arg0).getT_tittle());
		mhHolder.textView2.setText(list.get(arg0).getT_time());
		

		
		if(list.get(arg0).getPl_path().size()==0){
			mhHolder.imageView.setVisibility(View.GONE);
		}else{
			String url = "http://" + MyApplication.getIP() + ":8080/Jinnang/img/"
					+ list.get(arg0).getPl_path().get(0).getpl_path();
			Log.e("imagepath", url);
			mhHolder.imageView.setImageUrl(url);              
		}
		
		/*String url = "http://" + MyApplication.getIP() + ":8080/Jinnang/img/"
				+ list.get(arg0).getPl_path().get(0).getpl_path();
		Log.e("imagepath", url);
		mhHolder.imageView.setImageUrl(url);*/
		
		return arg1;
	}

}
